<?php
namespace Admin\Controller;

use Think\Controller;

class IndexController extends Controller
{
    public function index()
    {

        $this->display();
    }

    public function login()
    {
        if (IS_POST) {
            $data = I('post.');
            $admin = M('admin');
            $where['username'] = $data['username'];
            $where['password'] = md5($data['password']);
            $where['recode'] = md5($data['recode']);

            $ret = $admin->where($where)->find();
            if ($ret) {
                session('username', $where['username']);
                $this->success('登录成功', U('Main/config'));
            } else {
                $this->error('登录失败', U('Index/index'));
            }
        }
    }

    public function loginOut()
    {
        session('username', null);
        $this->success('退出成功!', U('Index/index'));
    }

}